
    /**  
    * @Title: BeanTableUtil.java
    * @Package com.frames.table
    * @Description: 
    * @author likai
    * @date 2017年5月7日
    * @version V1.0  
    */
    
package com.frames.table;

import java.util.Iterator;
import java.util.Map;

import com.utils.transtype.JsonObjectUtil;
import com.utils.transtype.TransType;

/**
    * @ClassName: BeanTableUtil
    * @Description: 对象表转换工具
    * @author likai
    * @date 2017年5月7日
    *
    */
@Deprecated
public class BeanTableUtil {

	/**
	 * @throws Exception 
	* @Title: 
	* @Description: 根据参数值获取表列
	* @param     参数
	* @return void    返回类型
	* @throws
	*/
	@SuppressWarnings("unchecked")
	public static String getColByParam(Object object) throws Exception {
		StringBuffer buffer=new StringBuffer();
		Map<String, Object> map=JsonObjectUtil.NON_NULL.beanToMap(object);
		Map<String, Object> data=JsonObjectUtil.NON_DEFAULT.beanToMap(object);
		String columns=(String) map.get("columns");
		Map<String, String> clownsMap=TransType.jsonToObject(columns, Map.class);
		Iterator<String> keys=data.keySet().iterator();
		while (keys.hasNext()) {
			String key= keys.next();
			if (data.get(key)!=null&&clownsMap.get(key)!=null) {
				buffer.append(clownsMap.get(key));
				buffer.append(",");
			}
			
		}
		String result=buffer.toString().length()==0?"":buffer.toString().substring(0,buffer.length()-1);
		return result;
	}
	/**
	 * @throws Exception 
	* @Title: 
	* @Description: 根据参数值获取值
	* @param     参数
	* @return void    返回类型
	* @throws
	*/
	@SuppressWarnings("unchecked")
	public static String getValByParam(Object object,String paramName) throws Exception {
		StringBuffer buffer=new StringBuffer();
		
		Map<String, Object> map=JsonObjectUtil.NON_NULL.beanToMap(object);
		Map<String, Object> data=JsonObjectUtil.NON_DEFAULT.beanToMap(object);
		String columns=(String) map.get("columns");
		Map<String, String> clownsMap=TransType.jsonToObject(columns, Map.class);
		Iterator<String> keys=data.keySet().iterator();
		while (keys.hasNext()) {
			String key= keys.next();
			if (data.get(key)!=null&&clownsMap.get(key)!=null) {
				buffer.append("#{");
				buffer.append(paramName);
				buffer.append(".");
				buffer.append(key);
				buffer.append("}");
				buffer.append(",");
			}
			
		}
		String result=buffer.toString().length()==0?"":buffer.toString().substring(0,buffer.length()-1);
		return result;
	}
	
	/**
	 * @throws Exception 
	* @Title: 
	* @Description: 根据参数值获取列名和值
	* @param     参数
	* @return void    返回类型
	* @throws
	*/
	@SuppressWarnings("unchecked")
	public static String getColVal(Object object,String paramName) throws Exception {
		StringBuffer buffer=new StringBuffer();
		Map<String, Object> map=JsonObjectUtil.NON_NULL.beanToMap(object);
		Map<String, Object> data=JsonObjectUtil.NON_DEFAULT.beanToMap(object);
		String columns=(String) map.get("columns");
		Map<String, String> clownsMap=TransType.jsonToObject(columns, Map.class);
		Iterator<String> keys=data.keySet().iterator();
		while (keys.hasNext()) {
			String key= keys.next();
			if (data.get(key)!=null&&clownsMap.get(key)!=null&&!clownsMap.get(key).equals("id")) {
				buffer.append(clownsMap.get(key));
				buffer.append("=#{");
				buffer.append(paramName);
				buffer.append(".");
				buffer.append(key);
				buffer.append("}");
				buffer.append(",");
			}
			
		}
		String result=buffer.toString().length()==0?"":buffer.toString().substring(0,buffer.length()-1);
		return result;
	}
	
	/**
	 * @throws Exception 
	* @Title: 
	* @Description: 根据参数值获取条件
	* @param     参数
	* @return void    返回类型
	* @throws
	*/
	@SuppressWarnings("unchecked")
	public static String getCondtionByParam(Object object,String paramName) throws Exception {
		StringBuffer buffer=new StringBuffer();
		Map<String, Object> map=JsonObjectUtil.NON_NULL.beanToMap(object);
		Map<String, Object> data=JsonObjectUtil.NON_DEFAULT.beanToMap(object);
		String columns=(String) map.get("columns") ;
		Map<String, String> clownsMap=TransType.jsonToObject(columns, Map.class);
		Iterator<String> keys=data.keySet().iterator();
		while (keys.hasNext()) {
			String key= keys.next();
			if (data.get(key)!=null&&clownsMap.get(key)!=null) {
				buffer.append(clownsMap.get(key));
				buffer.append("=#{");
				buffer.append(paramName);
				buffer.append(".");
				buffer.append(key);
				buffer.append("} and ");
			}
			
		}
		String condition=buffer.toString();
		if (condition.equals("")) {
			return "";
		}else {
			return " where "+buffer.toString().substring(0, buffer.lastIndexOf(" and "));
		}
	}

}
